﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace EdgeStatz.Controls
{
    public class AvailabilityTask
    {
        DateTime start;
        DateTime end;
        bool allDay;
        string subject;
        string message;
        Color color = Color.BlueViolet;

        public DateTime Start
        {
            get { return start; }
            set { start = value; }
        }
        public DateTime End
        {
            get
            {
                if (allDay)
                    return new DateTime(start.Year, start.Month, start.Day, 23, 59, 59);
                else
                    return end;
            }
            set { end = value; }
        }
        public bool AllDay
        {
            get { return allDay; }
            set { allDay = value; }
        }
        public string Subject
        {
            get { return subject; }
            set { subject = value; }
        }
        public string Message
        {
            get { return message; }
            set { message = value; }
        }
        public Color Color
        {
            set { color = value; }
            get { return color; }
        }

        /// <summary>
        /// Create a new CalenderTask object starting from now and lasting all day.
        /// </summary>
        public AvailabilityTask() : this(DateTime.Now, "", "") { }
        /// <summary>
        /// Create a new CalenderTask object from the start time and lasting all day.
        /// </summary>
        /// <param name="start">The start date and time of the task.</param>
        public AvailabilityTask(DateTime start) : this(start, "", "") { }
        /// <summary>
        /// Create a new CalenderTask object from the start time and lasting all day.
        /// </summary>
        /// <param name="start">The start date and time of the task.</param>
        /// <param name="subject">A short description that will be displayed on the calender.</param>
        public AvailabilityTask(DateTime start, string subject) : this(start, subject, "") { }
        /// <summary>
        /// Create a new CalenderTask object from the start time and lasting all day.
        /// </summary>
        /// <param name="start">The start date and time of the task.</param>
        /// <param name="subject">A short description that will be displayed on the calender.</param>
        /// <param name="message">A detailed message for the task.</param>
        public AvailabilityTask(DateTime start, string subject, string message)
        {
            this.start = start;
            this.allDay = true;
            this.subject = subject;
            this.message = message;
        }
        /// <summary>
        /// Create a new CalenderTask object from the start time and lasting all day.
        /// </summary>
        /// <param name="start">The start date and time of the task.</param>
        /// <param name="end">The end date and time of the task.</param>
        public AvailabilityTask(DateTime start, DateTime end) : this(start, end, "", "") { }
        /// <summary>
        /// Create a new CalenderTask object from the start time and lasting all day.
        /// </summary>
        /// <param name="start">The start date and time of the task.</param>
        /// <param name="end">The end date and time of the task.</param>
        /// <param name="subject">A short description that will be displayed on the calender.</param>
        public AvailabilityTask(DateTime start, DateTime end, string subject) : this(start, end, subject, "") { }
        /// <summary>
        /// Create a new CalenderTask object from the start time and lasting all day.
        /// </summary>
        /// <param name="start">The start date and time of the task.</param>
        /// <param name="end">The end date and time of the task.</param>
        /// <param name="subject">A short description that will be displayed on the calender.</param>
        /// <param name="message">A detailed message for the task.</param>
        public AvailabilityTask(DateTime start, DateTime end, string subject, string message)
        {
            if (end.CompareTo(start) < 0)
                throw new ArgumentException("End time must be equal to or after the start time");
            this.start = start;
            this.end = end;
            this.allDay = false;
            this.subject = subject;
            this.message = message;
        }
    }

    public class AvailabilityTaskCollection : IList<AvailabilityTask>, ICollection<AvailabilityTask>, IEnumerable<AvailabilityTask>
    {
        private List<AvailabilityTask> tasks = new List<AvailabilityTask> { };

        public int Count { get { return tasks.Count; } }

        public bool IsReadOnly { get { return false; } }

        public AvailabilityTask this[int index] { get { return tasks[index]; } set { tasks[index] = value; } }

        public void Add(AvailabilityTask value) { tasks.Add(value); }

        public void Clear() { tasks.Clear(); }

        public bool Contains(AvailabilityTask value) { return tasks.Contains(value); }

        public void CopyTo(AvailabilityTask[] array, int arrayIndex) { tasks.CopyTo(array, arrayIndex); }

        public int IndexOf(AvailabilityTask value) { return tasks.IndexOf(value); }

        public void Insert(int index, AvailabilityTask value) { tasks.Insert(index, value); }

        public bool Remove(AvailabilityTask value) { return tasks.Remove(value); }

        public void RemoveAt(int index) { tasks.RemoveAt(index); }

        public IEnumerator<AvailabilityTask> GetEnumerator() { return tasks.GetEnumerator(); }

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return tasks.GetEnumerator(); }
    }
}
